package logic

import (
	"context"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *srv.OrderListRequest) (*srv.OrderListResponse, error) {
	// todo: add your logic here and delete this line

	var order []mysql.Order
	mysql.DB.Find(&order)
	var lists []*srv.OrderList
	for _, m := range order {
		list := srv.OrderList{
			OrderId:  int64(m.ID),
			UserId:   int64(m.UserId),
			OrderNum: m.OrderNum,
			PayType:  int64(m.PayType),
			PayState: int64(m.PayState),
			PayPrice: float32(m.PayPrice),
			PayTime:  m.PayTime,
		}
		lists = append(lists, &list)
	}

	return &srv.OrderListResponse{List: lists}, nil
}
